# -----------------gevent接口遇到IO等待操作实现自动切换---------------------
import requests,time,gevent
t1=time.time()
def f(url):
    print("GET: %s" % url)
    resp =requests.get(url)
    data=resp.text
    f= open("new.html","w",encoding="utf8")
    f.write(data)
    print("%d bytes recevied from %s" %(len(data),url))
gevent.joinall([
    gevent.spawn(f,"https://www.bilibili.com/video/av21663728/?p=325"),
    gevent.spawn(f,"http://news.baidu.com/"),
    gevent.spawn(f,"http://www.okoook.com/"),
    gevent.spawn(f,"https://www.imooc.com/"),
    gevent.spawn(f,"http://www.xiaohuar.com/"),
    gevent.spawn(f,"http://www.xiaohuar.com/hua/"),
])
# print(time.time()-t1)

#
# f("https://www.bilibili.com/video/av21663728/?p=325")
# f("http://news.baidu.com/")
f("http://www.okoook.com/")
# f("https://www.imooc.com/")
# f("http://www.xiaohuar.com/")
# f("http://www.xiaohuar.com/hua/")

print(time.time()-t1)